﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="getmac.aspx.cs" Inherits="TradeTestWeb.getmac" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function showMacAddress() {
            var obj = null;
            try {
                obj = new ActiveXObject("WbemScripting.SWbemLocator");
            } catch (ex) {
                alert(ex.message);
                return;
            }
            var s = obj.ConnectServer(".");
            var properties = s.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
            var e = new Enumerator(properties);


            var output;
            output = '<table border="0" cellPadding="5px" cellSpacing="1px" bgColor="#CCCCCC">';
            output = output + '<tr bgColor="#EAEAEA"><td>Caption</td><td>MACAddress</td></tr>';
            while (!e.atEnd()) {
                e.moveNext();
                var p = e.item();
                if (!p) continue;
                if (p.MACAddress == null) {
                    continue;
                }
                output = output + '<tr bgColor="#FFFFFF">';
                output = output + '<td>' + p.Caption; +'</td>';
                output = output + '<td>' + p.MACAddress + '</td>';
                output = output + '</tr>';
            }

            output = output + '</table>';
            document.getElementById("box").innerHTML = output;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" value="脚本获取,安全设置可能会导致出错" onclick="showMacAddress()" />
    </div>
    <div id="box">
    </div>
    </form>
</body>
</html>
